package com.lezhi.socialgram.api.sys;

import com.lezhi.socialgram.model.sys.UserPrivacy;
import com.lezhi.socialgram.model.sys.UserPush;
import com.lezhi.socialgram.service.sys.UserSettingsService;
import com.lezhi.socialgram.util.Result;
import com.lezhi.socialgram.util.ValidUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Created by daizhen on 2017/4/5.
 */
@RestController
public class UserSettingsApi {

    private static final Logger logger = LoggerFactory.getLogger(UserSettingsApi.class);

    @Autowired
    UserSettingsService userSettingsService;

    @PostMapping("/userPrivacy")
    public Result setUserPrivacy(@RequestBody @Valid UserPrivacy userPrivacy, BindingResult bindingResult) {
        ValidUtils.valid(logger, bindingResult);
        return userSettingsService.setUserPrivacy(userPrivacy);
    }

    @GetMapping("/userPrivacy/{userId}")
    public Result getUserPrivacy(@PathVariable("userId") Long userId) {
        return userSettingsService.queryPrivacyById(userId);
    }

    @PostMapping("/userPushSetting")
    public Result setUserPush(@RequestBody @Valid UserPush userPush, BindingResult bindingResult) {
        ValidUtils.valid(logger, bindingResult);
        return userSettingsService.setUserPush(userPush);
    }

    @GetMapping("/userPushSetting/{userId}")
    public Result getUserPush(@PathVariable("userId") Long userId) {
        return userSettingsService.queryPushById(userId);
    }

}
